# Presented By ZhaoEnxing
# time: 2021/10/15 15:22
# 我们假设有6个顾客进入某服装店,而任一顾客购买的概率是0.30。
# 计算下列事件的概率:(1)恰有4个顾客购买;(2)购买的顾客不超过一半;(3)至少有一个顾客购买。
# (1)二项分布 n = 6, p=0.3   P(X=k)=Ck6 * 0.3^k * (1-0.3)^6-k

from scipy.stats import binom

import numpy as np
import matplotlib.pyplot as plt
import math
from scipy import stats
print("--------------(1)恰恰有三个购买----------------")
n = 6
p = 0.3
k=4
binomial1 = stats.binom.pmf(k, n, p)
print(binomial1)
print("--------------(2)购买的不超过一半---------------")
binomial2=0
for k in range(4):
    binomial = stats.binom.pmf(k, n, p)
    binomial2 = binomial2+binomial
print(binomial2)
print("--------------(3)至少一个购买------------------")
#P(x>=1)=1-P(X=0)
n = 6
p = 0.3
k=0
binomial = stats.binom.pmf(k, n, p)
binomial3=1-binomial
print(binomial3)

